﻿using System;
using System.Globalization;
using System.Xml;
using System.Xml.Serialization;

namespace openSourceC.DaylifeClient
{
	/// <summary>
	///		Summary description for Video.
	/// </summary>
	[Serializable]
	[XmlType("video")]
	public class Video
	{
		/// <summary></summary>
		[XmlElement("caption")]
		public string Caption { get; set; }

		/// <summary>Gets or sets the content type.</summary>
		[XmlElement("content_type")]
		public string ContentType { get; set; }

		/// <summary>Gets or sets the Url of the video content.</summary>
		[XmlElement("content_url")]
		public string ContentUrl { get; set; }

		/// <summary></summary>
		[XmlElement("credit")]
		public string Credit { get; set; }

		/// <summary></summary>
		[XmlElement("headline")]
		public string Headline { get; set; }

		/// <summary></summary>
		[XmlElement("media_topic_relevance")]
		public int? MediaTopicRelevance { get; set; }

		/// <summary></summary>
		[XmlElement("page_url")]
		public string PageUrl { get; set; }

		/// <summary></summary>
		[XmlElement("source")]
		public Source Source { get; set; }

		/// <summary></summary>
		[XmlElement("thumb_url")]
		public string ThumbUrl { get; set; }

		/// <summary>Gets or sets the time stamp of the image expressed as a <see cref="DateTimeOffset"/>.</summary>
		[XmlIgnore]
		public DateTimeOffset? TimestampValue { get; set; }

		/// <summary>Gets or sets the time stamp of the image expressed in UTC.</summary>
		[XmlElement("timestamp")]
		public string Timestamp
		{
			get { return TimestampValue.HasValue ? TimestampValue.Value.ToString(DaylifeExtensions.TimestampFormat) : null; }

			set
			{
				if (string.IsNullOrEmpty(value))
				{
					TimestampValue = null;
				}
				else
				{
					TimestampValue = DateTimeOffset.ParseExact(value, DaylifeExtensions.TimestampFormat, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
				}
			}
		}

		/// <summary>Gets or sets the time stamp epoch (UNIX time) expressed in UTC.</summary>
		[XmlElement("timestamp_epoch")]
		public int? TimestampEpochValue { get; set; }

		/// <summary></summary>
		[XmlElement("video_id")]
		public string VideoId { get; set; }


		/// <summary>Gets or sets the array of all the out-of-band elements.</summary>
		[XmlAnyElement]
		public XmlElement[] ZElements { get; set; }
	}
}
